package com.itgungnir.diyshuo.fragment.danpin_fragment;

import com.itgungnir.diyshuo.bean.DiyBean;
import com.itgungnir.diyshuo.http.GvRetrofitService;
import com.itgungnir.diyshuo.http.HttpHelper;

import java.util.Map;

import retrofit2.Retrofit;
import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 单品页面的Model类
 */
public class DanPinModel implements DanPinContract.Model {


    @Override
    public void getDanPinData(Map<String, String> params, final DanPinContract.OnLoadDanPinListener loadDanPinListener) {
        Retrofit retrofit= HttpHelper.getInstance().getRetrofit();
        Observable<DiyBean> observable=retrofit.create(GvRetrofitService.class).getData(params);
        observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<DiyBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(DiyBean diyBean) {
                loadDanPinListener.onSuccess(diyBean);
            }
        });
    }
}